package com.wangyb.wework.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wangyb.wework.enums.updatetime.TypeEnum;
import com.wangyb.wework.entity.WwUpdateTime;
import com.wangyb.wework.mapper.WwUpdateTimeMapper;
import com.wangyb.wework.service.IWwUpdateTimeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * 同步时间Service业务层处理
 *
 * @Author: wangyb
 * @Date: 2021/6/28 2:13 下午
 */
@Service
public class WwUpdateTimeServiceImpl extends ServiceImpl<WwUpdateTimeMapper, WwUpdateTime> implements IWwUpdateTimeService {
	@Autowired
	private WwUpdateTimeMapper wwUpdateTimeMapper;
	@Override
	public void updateSynTime(Long corpId, TypeEnum typeEnum) {
		if (corpId == null) {
			return;
		}

		// 更新 mc_work_update_time
		WwUpdateTime entity = new WwUpdateTime();
		entity.setCorpId(corpId);
		entity.setType(typeEnum.getCode());
		entity = wwUpdateTimeMapper.selectOne(new QueryWrapper<>(entity));
		if (entity == null) {
			entity = new WwUpdateTime();
			entity.setCorpId(corpId);
			entity.setType(typeEnum.getCode());
			entity.setLastUpdateTime(new Date());
			wwUpdateTimeMapper.insert(entity);
		} else {
			entity.setLastUpdateTime(new Date());
			wwUpdateTimeMapper.updateById(entity);
		}
	}

	@Override
	public String getLastUpdateTime(TypeEnum typeEnum) {
		return null;
	}

	@Override
	public WwUpdateTime getWwUpdateTimeByCorpIdType(Long corpId, int code) {
		return null;
	}

	@Override
	public Integer updateWorkUpdateTimeById(Long id, WwUpdateTime wwUpdateTime) {
		return null;
	}

	@Override
	public Integer createWorkUpdateTime(WwUpdateTime wwUpdateTime) {
		return null;
	}
}
